Programming Questions for Practice
A combined Salsa Lesson is to be conducted for two different classes having 8 students each in a school. There are two queues of students, queue A and queue B. You are given a string A denoting the queue sequence of students in queue A and string B denoting the queue sequence of students in queue B. A good pair is a pair containing one boy and one girl. Pairing the students at Nth position of queue A with the student at Nth position of queue B is the only possible method of pairing. Write a program to help the organiser count the total number of good pairs that will be formed, when the students are paired according to the method above. Your task is to return the percentage of good pairs among the total number of pairs that will be formed.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
A combined Salsa Lesson is to be conducted for two different classes having 8 students each in a school.
There are two queues of students, queue A and queue B. You are given a string "A" denoting the queue
sequence of students in queue A and string "B" denoting the queue sequence of students in queue B.
A good pair is a pair containing one boy and one girl. Pairing the students at Nth position of queue A
with the student at Nth position of queue B is the only possible method of pairing.
Write a program to help the organiser count the total number of good pairs that will be formed,
when the students are paired according to the method above.
Your task is to return the percentage of good pairs among the total number of pairs that will be formed.
*/
int good_pairs(char *A, char *B) {
int count = 0, i;
float result;
for(i = 0; i < 8; i++) {
if(A[i] != B[i])
count++;
}
result = (float)count / 8 * 100;
return (int)result;
}
int main()
{
int result = good_pairs("00110100", "00000111");
printf("Percentage of good pairs = %d\n", result);
return 0;
}